package com.oa.controller;

import com.oa.vo.Message;
import com.oa.vo.Page;
import com.oa.vo.Result;
import com.oa.pojo.Role;
import com.oa.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@CrossOrigin
@ResponseBody
@Controller
public class RoleConntroller {

    @Autowired
    private RoleService roleService;

    @RequestMapping(value = "/getRolePage")
    public Result getRolePage(Integer pageNo,Integer pageSize){
        if(pageNo == null){
            pageNo=1;
        }
        if(pageSize == null){
            pageSize=3;
        }

        Page rolePage = roleService.getRolePage(pageNo, pageSize);
        Message message = new Message();
        Result result = new Result();
        result.setMessage(message);
        result.setData(rolePage);
        return result;
    }

    @RequestMapping(value = "/getRole")
    public Result getRole(Integer roleId){
        Role role = roleService.getRole(roleId);
        Result result = new Result();
        result.setData(role);
        return result;
    }

    @RequestMapping(value = "/addRole")
    public Result addRole(@RequestBody Role role){
        System.out.println(role);
        roleService.addRole(role);
        Result result = new Result();
        return result;
    }

    @RequestMapping(value = "/deleteRole")
    public Result deleteRole(Integer roleId){
        System.out.println(roleId);
        roleService.deleteRole(roleId);
        Result result = new Result();
        return result;
    }

    @RequestMapping(value = "/updateRole")
    public Result updateRole(@RequestBody Role role){
        System.out.println(role);
        roleService.updateRole(role);
        Result result = new Result();
        return result;
    }

}
